{extend name="common/base"/}
{block name="style"}
<style>
	.gougu-upload-files{background-color: #ffffff; border:1px solid #e4e7ed;color: #c0c4cc;cursor: not-allowed; padding:0 12px; width:180px; box-sizing: border-box; display: inline-block; font-size: inherit; height: 38px; line-height: 35px; margin-right:8px; border-radius:2px;}
	.gougu-upload-tips{color:#969696}
	.layui-form-item{margin-bottom:8px;}
	.layui-input-block{min-height:24px;}
</style>
{/block}
<!-- 主体 -->
{block name="body"}
<div class="p-3">
	<table class="layui-hide" id="treeTableCase" lay-filter="treeTableCase"></table>
	<input type="hidden" id="matter_id"  value="{$matter_id}">
</div>
<script type="text/html" id="toolbarDemo">
	<div class="layui-btn-container">
		<button class="layui-btn layui-btn-sm add-menu" type="button">+ 添加情形</button>
	</div>
</script>

<script type="text/html" id="barDemo">
	<div class="layui-btn-group"><span class="layui-btn layui-btn-xs" lay-event="edit">编辑</span><span class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</span></div>
</script>
{/block}
<!-- /主体 -->

<!-- 脚本 -->
{block name="script"}
<script>
	const moduleInit = ['tool', 'treeGrid','oaTool'];
	function gouguInit() {
		var table = layui.table, tool = layui.tool ,form = layui.form,laydate = layui.laydate,upload=layui.upload,treeGrid = layui.treeGrid,oaTool = layui.oaTool,element = layui.element;
		//情形列表
		let matter_id = $('#matter_id').val();
		if(!matter_id){
			matter_id = 0;
		}
		var pageTable = treeGrid.render({
			id: 'treeTableCase'
			,toolbar: '#toolbarDemo'
			, elem: '#treeTableCase'
			, idField: 'id'
			, url: "/matter/matter_case/index"
			, where:{matter_id:matter_id}
			, cellMinWidth: 80
			, treeId: 'id'//树形id字段名称
			, treeUpId: 'pid'//树形父id字段名称
			, treeShowName: 'name'//以树形式显示的字段
			, height: 'full-0'
			,isOpenDefault:true
			, cols: [[
				{ field: 'id', width: 100, title: 'ID号', align: 'center' }
				, { field: 'pid', title: '上级情形ID',width: 120, align: 'center'}
				, { field: 'name', title: '情形描述'}
				, { field: 'material_list', title: '材料',width: 500}
				, { width:180, title: '操作', align: 'center', templet: function (d) {
						var html = '<span class="layui-btn-group"><button type="button" class="layui-btn layui-btn-xs" lay-event="add">添加下级情形</button><button type="button" class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</button><button type="button" class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</button></span>';
						return html;
					}
				}
			]]
			, page: false
		});
		//表头工具栏事件
		$('body').on('click','.add-menu', function(){
			tool.side("/matter/matter_case/add?matter_id="+matter_id);
			return;
		});
		//操作按钮
		treeGrid.on('tool(treeTableCase)', function (obj) {

			if (obj.event === 'add') {
				tool.side("/matter/matter_case/add?pid="+obj.data.id+"&matter_id="+matter_id);
				return false;
			}
			if (obj.event === 'edit') {
				tool.side("/matter/matter_case/add?id="+obj.data.id+"&matter_id="+matter_id);
				return false;
			}

			if (obj.event === 'del') {
				layer.confirm('确定要删除吗?', {icon: 3, title:'提示'}, function(index){
					let callback = function (e) {
						layer.msg(e.msg);
						if (e.code == 0) {
							obj.del();
						}
					}
					tool.delete("/matter/matter_case/delete", { id: obj.data.id }, callback);
					layer.close(index);
				});
			}

		});
	}
</script>
{/block}
<!-- /脚本 -->
